package com.flyiu.data.consistency.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import com.flyiu.foundational.entity.BaseEntity;

import lombok.Data;

@Data
@Entity
public class DistributedTransactionInstance extends BaseEntity{

    private String                              name;

    @Column(name = "business_id", unique = true)
    private String                              businessId;

    @Column(name = "transaction_state")
    @Enumerated(value = EnumType.STRING)
    private DistributedTransactionState         transactionState;
    @OneToMany(mappedBy = "instance")
    private List<DistributedTransactionPartner> partners;

    public List<DistributedTransactionPartner> getPartners() {
        if (partners == null) {
            partners = new ArrayList<>();
        }
        return partners;
    }

}
